package cn.zuo.utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @Author 白白旧维
 * @Date 2021/7/9 10:55
 */
public class SHA256 {

    private static String salt = "doge666";//盐值

    public static String sha256(String m){
        m = m+salt;
        MessageDigest sha256 = null;
        try {
            sha256 = MessageDigest.getInstance("SHA-256");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        byte[] sha256Bytes = sha256.digest(m.getBytes());
        return binary(sha256Bytes,16);
    }


    private static String binary(byte[] bytes, int radix){
        return new BigInteger(1, bytes).toString(radix);// 这里的1代表正数
    }


}
